<?php

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use kartik\select2\Select2;
use dosamigos\tinymce\TinyMce;

$city = Yii::$app->params['city'];

(new \Collator('zh-CN'))->asort($city);

$days = $nights = range(0,35,1);

unset($days[0]);
unset($nights[0]);


?>

<?=  yii\web\View::registerCssFile("/css/handsontable.full.css") ?>
<div class="template-form">
    <?php $form = ActiveForm::begin([
                                     'layout' => 'horizontal',
                                     'id' => 'template-form',
                                     'fieldConfig' => [
                                        'template' => "{label}\n{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}",
                                        'horizontalCssClasses' => [
                                            'label' => 'col-sm-2',
                                            'wrapper' => 'col-sm-7',
                                            'error' => '',
                                        ],
                                     ],
                                ]); ?>



    <?= $form->field($model, 'cruise_id')->label(false)->hiddenInput() ?>
    <?= $form->field($model, 'id')->label(false)->hiddenInput() ?>

    <?php  echo $form->field($model, 'from_city')->dropdownList($city, ['prompt'=>'选择出发城市']) ?>

    <?php  echo $form->field($model, 'to_city')->dropdownList($city, ['prompt'=>'选择返港城市']) ?>

    <?php  echo $form->field($model, 'go_city')->dropdownList($city, ['prompt'=>'选择上船城市']) ?>

    <?php  echo $form->field($model, 'return_city')->dropdownList($city, ['prompt'=>'选择下船城市']) ?>

  <!--   </?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?> -->

    <?= $form->field($model, 'pass_city')->textInput(['maxlength' => true]) ?>

    <div class="row">
        <div class="col-md-2" style="text-align: right;">
            <label >所需时间</label>
        </div>
        <div class="form-inline col-md-10"> 
            <?= $form->field($model, 'nights',['template'=>'<div class="col-md-2">{input}{error}</div>'])->dropdownList($nights)->label(false) ?>
            <label>晚&nbsp;&nbsp;</label>
            <?= $form->field($model, 'days',['template'=>'{label}<div class="col-md-2">{input}{error}</div>'])->dropdownList($days)->label(false) ?>
            <label>天</label>
        </div>
    </div>

    <?= $form->field($model, 'line',['template'=>'{label}<div class="col-md-3">{input}{error}</div>'])->widget(Select2::classname(), [
                'data' => Yii::$app->params['line'],
                'language' => 'zh-cn',
                'options' => ['placeholder' => '选择航线....'],
                'pluginOptions' => [
                    'allowClear' => true,
                ],
            ]) ?>

    <?= $form->field($model, 'type')->inline(true)->radioList(\Yii::$app->params['product_type']) ?>

    <!--?= $form->field($model, 'cost')->widget(TinyMce::className(), [
        'options' => ['rows' => 10],
        'language' => 'zh_CN',
        'clientOptions' => [
            'plugins' => [
                "code advlist autolink lists link charmap print preview anchor",
                "searchreplace visualblocks code fullscreen template  preview ",
                "insertdatetime media table contextmenu paste  image "
            ],
            'toolbar' => "code undo redo | styleselect | bold italic  | link preview template",
            'menubar' => 'file',
            'templates' => '/templates/trip.php', // template
            'plugin_preview_width' => 420,           // preview
        ]
    ]); ? -->

    <?= $form->field($model, 'cost')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>

    <?= $form->field($model, 'nocost')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>

    <?= $form->field($model, 'cancel')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>

    <?= $form->field($model, 'discount')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>

    <?= $form->field($model, 'visa')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>

    <?= $form->field($model, 'signup')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>

    <?= $form->field($model, 'land')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>

    <?= $form->field($model, 'expense')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>
    <?= $form->field($model, 'special')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>
    <?= $form->field($model, 'important')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>
    <?= $form->field($model, 'safe_1')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>
    <?= $form->field($model, 'safe_2')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>
    <?= $form->field($model, 'safe_3')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>





    <!-- ?= $form->field($model, 'visa')->widget(TinyMce::className(), [
        'options' => ['rows' => 10],
        'language' => 'zh_CN',
        'clientOptions' => [
            'plugins' => [
                "code advlist autolink lists link charmap print preview anchor",
                "searchreplace visualblocks code fullscreen template  preview ",
                "insertdatetime media table contextmenu paste  image "
            ],
            'toolbar' => "code undo redo | styleselect | bold italic  | link preview template",
            'menubar' => 'file',
            'templates' => '/templates/trip.php', // template
            'plugin_preview_width' => 420,           // preview
        ]
    ]); ? -->

    <?= $form->field($model, 'status')->inline(true)->radioList(\Yii::$app->params['status']) ?>
    <?= $form->field($model, 'trip')->label(false)->hiddenInput() ?>

    <div class="row">
        <div data-jsfiddle="example1" class="ajax-container">
              <pre id="example1console" class="console">行程信息</pre>
              <div id="handson" class="hot handsontable htRowHeaders htColumnHeaders "></div>
        </div>
    </div>
    
    <hr>
    <div class="form-group text-center">
        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>
</div>
<?php app\components\JsBlock::begin() ?>
<script >
    $(function(){
        var
         container = document.getElementById('handson'),
         hot;

        hot = new Handsontable(container, {
           //data: data,
           contextMenu: true,
           startRows: 1,
           startCols: 18,
           stretchH: 'all',
           colWidths: [120,50,50,50,50,50,300,50],
           colHeaders: ['标题', '餐饮', '住宿','国家城市', '抵达时间','起航时间','描述','类型'],
           columns: [
                 //{data: "id", type: 'numeric', readOnly:true},
                 {data: "title", type: 'text'},
                 {data: "eat", type: 'text'},
                 {data: "room", type: 'text'},
                 {data: "country", type: 'text'},
                 {data: "time1", type: 'text'},
                 {data: "time2", type: 'text'},
                 {data: "desc", type: 'text'},
                 {data: "type", type: 'dropdown', source: ['出发','登船','海上巡游','岸上游览', '返回','飞机'] }
               ],
        });

            
        var id = $("#template-id").val();
        if(id){
            // 加载默认数据
            $.get('/product/template/getdata', {id : id}, function(res) {
                var data = JSON.parse(res);

                if(data != ''){
                    hot.loadData(data);
                }
            });
        }

        $("#template-form").submit(function(){

            //var data = hot.getData();
            var data = JSON.stringify({trip: hot.getData()});

            $("#template-trip").val(data);
           // return false;
        });

    });

</script>
<?php app\components\JsBlock::end() ?>
<?=  yii\web\View::registerJsFile("/js/handsontable.full.js",['position'=>yii\web\View::POS_END]) ?>
